import requests
import re
from bs4 import BeautifulSoup

target_url = 'https://www.sjxs.la/book/71847/'
res = requests.get(target_url)
res.encoding = 'utf-8'
html = res.text
bs = BeautifulSoup(html, 'lxml')

results = bs.find_all('ul')
ress = results[2]
rrr = ress.find_all('li')
for r in rrr:
    url = target_url + r.find('a').get('href')
    res2 = requests.get(url)
    res2.encoding = 'utf-8'
    html2 = res2.text
    bs2 = BeautifulSoup(html2, 'lxml')
    results2 = bs2.find(id='content1')
    f= open('./text.txt', 'a', encoding='utf-8')
    f.write(results2.get_text())